package healththink



import grails.test.mixin.*
import org.junit.*

/**
 * See the API for {@link grails.test.mixin.domain.DomainClassUnitTestMixin} for usage instructions
 */
@TestFor(FacilityAttributeLink)
@Mock([Facility, Attribute])
class FacilityAttributeLinkTests {

	@Test
    void testFacilityAttributeLink() {
		
		def falTest = HealthThink.getStaticFacilityAttributeLink()
		mockForConstraintsTests(FacilityAttributeLink, [falTest])
		def falTest1 = new FacilityAttributeLink()
		assertFalse falTest1.validate()
		assertEquals "nullable", falTest1.errors["attribute"]
		
		/* usage test */
		Attribute fa = HealthThink.getStaticFacilityAttribute()
		Facility fac = HealthThink.getStaticFacility()
		
		FacilityAttributeLink target = FacilityAttributeLink.link(fa, fac)
		
		assertNotNull("(error)FacilityAttributeLink Target Null", target)
		assertNotNull("(error)FacilityAttributeLink Validation Was Not Successfull", target.validate())
		
		target = target.save(flush:true)
		FacilityAttributeLink expected = FacilityAttributeLink.findById(target.id)
		
		assertNotNull("(error)FacilityAttributeLink Target was not saved", target)
		assertNotNull("(error)Expected FacilityAttributeLink was null", expected)
		assertEquals("(error)Target and Expected are not Equal", target, expected)
	   
		target.delete(flush:true)
    }
}
